# coding=UTF-8
import sys
import datetime
import io

file = io.open("/root/movie/file/movie.csv",'w',encoding="utf-8")
def getFileContext():
    with io.open("/root/movie/file/u.data", "r+") as f:
        context = f.readlines()
        for line in context:
            #去除空格
            line = line.strip()
            #挨个赋值
            userid, movieid, rating, unixtime = line.split('\t')
            #将时间戳转化为日期
            date = datetime.datetime.fromtimestamp(float(unixtime))
            #获取工作日（周一……周天）
            weekday = date.weekday()
            #写入csv文件
            text = u"{},{},{},{}\n".format(userid, movieid, rating, str(weekday))
            file.write(text)
            file.flush()
getFileContext()
file.close()
